package ru.gerunn.clarg;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CLParser {

	public static void parse(String[] arg, CLArg clArg) {
		Pattern pattern = Pattern.compile("^-(.*)$");
		Matcher matcher;
		int i = -1;
		while (i < arg.length - 1) {
			i = i + 1;
			matcher = pattern.matcher(arg[i]);
			if (matcher.matches()) {
				String name = arg[i];
				clArg.enable(name);
				i = i + 1;
				while(i < arg.length && !pattern.matcher(arg[i]).matches()) {
					clArg.add(name, arg[i]);
					i = i + 1;
				}
				i = i - 1;
			} else {
				clArg.add(arg[i]);
			}
		}
	}

	public static void main(String[] arg) {
		CLArg clArg = new CLArg();
		arg = new String[9];
		arg[0] = "a1";
		arg[1] = "'a2'";
		arg[2] = "a3";
		arg[3] = "-a4";
		arg[4] = "a4a1";
		arg[5] = "-a5";
		arg[6] = "a5a1";
		arg[7] = "a5a2";
		arg[8] = "-a6";
		parse(arg, clArg);
		//clArg.add("asd", "asd");
		//clArg.add("asd", "zxc");
		//clArg.add("zxc", "zxc1");
		//clArg.add("zxc", "zxc2");

		//System.out.println(clArg.get(2));
		//System.out.println(clArg.get("-asd"));
		//System.out.println(clArg.get("-qwe"));
		//System.out.println(clArg.get("-zxc") == null);
		//System.out.println(clArg.get("-asd", 0));
		//System.out.println(clArg.get("-qwe", 1));
		
		System.out.println(clArg.getCL());
	}
}
